home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / support / easy1541 / dev / iec.doc < prev    next >
Text File  |  1999-01-01  |  12KB  |  486 lines

  1. TABLE OF CONTENTS
  2.  
  3. iec.library/--background
  4. iec.library/ACPtr
  5. iec.library/CIOut
  6. iec.library/Listen
  7. iec.library/Second
  8. iec.library/Talk
  9. iec.library/TkSA
  10. iec.library/UnListen
  11. iec.library/UnTalk
  12. iec.library/--background                             iec.library/--background
  13.  
  14. Disclaimer: information contained herein is not wholly proven reliable.
  15. I didn't find enough official documentation about IEC interface and DOS
  16. standards, so I examined the original ROM disassemble, some C64 disk
  17. utilities and some Commodore 64 Emulators.
  18. If you find something wrong, or own better specifications, please contact me.
  19.  
  20.  
  21. Fabrizio Farenga
  22. (f.farenga@agora.stm.it)
  23.  
  24.  
  25.  
  26.   THE SERIAL BUS
  27.  
  28.     The IEC serial bus is a daisy chain arrangement designed to let the
  29.   computer communicate with devices such as the VIC-1541 DISK DRIVE and
  30.   the VIC-1525 GRAPHICS PRINTER. The advantage of the serial bus is that
  31.   more than one device can be connected to the port. Up to 5 devices can be
  32.   connected to the serial bus at once.
  33.     There are three types of operation over a serial bus: CONTROL, TALK, and
  34.   LISTEN. A CONTROLLER device is one which controls operation of the serial
  35.   bus. A TALKER transmits data onto the bus. A LISTENER receives data from
  36.   the bus.
  37.     The computer is the controller of the bus. It also acts as a TALKER
  38.   (when sending data to the drive, for example) and as a LISTENER (when
  39.   loading a program from the disk drive, for example). Other devices may be
  40.   either LISTENERS (the printer), TALKERS, or both (the disk drive). Only
  41.   the computer can act as the controller.
  42.     All devices connected on the serial bus will receive the whole data
  43.   transmitted over the bus. To allow the computer to route data to its
  44.   chosen destination, each device has a bus ADDRESS. By using this device
  45.   address, the computer can control access to the bus. Addresses on the
  46.   serial bus range from 4 to 31.
  47.     The computer can COMMAND a particular device to TALK or LISTEN.
  48.   When the computer commands a device to TALK, the device will begin
  49.   putting data onto the serial bus. When the computer commands a device
  50.   to LISTEN, the device addressed will get ready to receive data (from the
  51.   computer or from another device on the bus). Only one device can TALK
  52.   on the bus at once; otherwise, the data will collide and the system
  53.   will crash in confusion. However, any number of devices can LISTEN at the
  54.   same time to one TALKER.
  55.  
  56.  
  57.   A SAMPLE TRANSMISSION
  58.  
  59.   The basic operations, during a trasmission from computer to drive are the
  60.   following:
  61.  
  62.   - OPEN TRASMISSION
  63.   - SEND DATA
  64.   - CLOSE TRASMISSION
  65.  
  66.   This can occur when we want to send a single command to the drive, and we
  67.   don't ask for reply. As example we could send the "I" command to the
  68.   drive unit 8 to reset it.
  69.  
  70.   In Commodore Basic v2.0 we should use something like:
  71.  
  72.   1 OPEN 1,8,15
  73.   2 PRINT #1,"I"
  74.   3 CLOSE 1
  75.  
  76.   - In the first line we ask to open a logic file number (1), to the device
  77.     number 8 (the drive) on the command channel (15).
  78.  
  79.   - In the second line we send to the logic file 1 (after the previous OPEN,
  80.     it refers to the device number 8) the "I" character.
  81.  
  82.   - In the third line we CLOSE the logic file number 1.
  83.  
  84.   Now the drive will be reset.
  85.  
  86.  
  87.   Doing the same operations, using the iec.library functions and 'C'
  88.   language is easy:
  89.  
  90.   /* Step 1 */
  91.   Listen(8);
  92.   Second(CMD_OPEN+15)
  93.   UnListen();
  94.  
  95.   /* Step 2 */
  96.   Listen(8);
  97.   Second(CMD_DATA+15)
  98.   CIOut('I');
  99.   UnListen();
  100.  
  101.   /* Step 3 */
  102.   Listen(8);
  103.   Second(CMD_CLOSE+15)
  104.   UnListen();
  105.  
  106.   Step 1  the device 8 (we suppose a 1541 drive) will become a LISTENER.
  107.           We send it a secondary address to perform an open command on the
  108.           channel 15 (command channel). Then we end the opening session,
  109.           ordering to the device to UNLISTEN.
  110.  
  111.   Step 2  the device 8 will become a LISTENER again. We notify by using
  112.           the secondary address that we are going to send data. Using the
  113.           CIOut() function, we send the 'I' character, then close the data
  114.           trasmission.
  115.  
  116.   Step 3  we end up operations sending a secondary address that includes
  117.           the CMD_CLOSE command.
  118.  
  119.  
  120.  
  121.   Please refer to the example sources to obtain further information.
  122.  
  123.  
  124.  
  125. Note: don't issue any command to the 1541 if it is connected but turned
  126.       off. Due to an odd bug, you'll not get the "DEVICE NOT PRESENT
  127.       ERROR" and you'll lock up the Amiga! If the 1541 is physically
  128.       disconnected, you'll get the proper error.
  129.  
  130.  
  131.  
  132. iec.library/ACPtr                                           iec.library/ACPtr
  133.  
  134.    NAME
  135.     ACPtr -- Input byte from serial port.
  136.  
  137.    SYNOPSIS
  138.     char = ACPtr()
  139.     D0
  140.  
  141.     LONG ACPtr(void)
  142.  
  143.  
  144.    FUNCTION
  145.     This is the function to use when you want to get information from a
  146.     device on the serial bus, like a disk drive. This function gets one
  147.     data byte from the serial bus using full handshaking. A -1 is
  148.     returned when EOF or an error is encountered. To prepare for this
  149.     function the Talk() function must be called first to command the
  150.     device on the serial bus to send data through the bus. If the input
  151.     device needs a secondary command, it must be sent by using the TkSA()
  152.     function before calling this function.
  153.  
  154.  
  155.     How to Use:
  156.  
  157.      1) Command a device on the serial bus to prepare to send data to
  158.         the computer. (Use the Talk() and TkSA() functions.)
  159.      2) Call this function
  160.      3) Print or otherwise use the data.
  161.  
  162.  
  163.    INPUTS
  164.  
  165.  
  166.    RESULTS
  167.     char - character read (0-255)
  168.  
  169.  
  170.    EXAMPLE
  171.  
  172.     /*GET A BYTE FROM THE BUS*/
  173.  
  174.     UBYTE c;
  175.  
  176.     c=ACPtr();
  177.     printf ("Byte received - %d\n",c);
  178.  
  179.  
  180.    BUGS
  181.  
  182.  
  183.    SEE ALSO
  184.     Talk(), TkSA()
  185.  
  186. iec.library/CIOut                                           iec.library/CIOut
  187.  
  188.    NAME
  189.     CIOut -- Output byte to serial port.
  190.  
  191.    SYNOPSIS
  192.     CIOut(CHAR)
  193.           D0
  194.  
  195.     void CIOut(char)
  196.  
  197.  
  198.    FUNCTION
  199.     This function is used to send information to devices on the serial
  200.     bus. A call to this function will put one data byte onto the serial
  201.     bus using full serial handshaking. Before this function is called,
  202.     the Listen() function must be used to command a device on the serial
  203.     bus to get ready to receive data (if a secondary address is needed,
  204.     this must also be sent by using the Second() function). Device must
  205.     be listening or the status word will return a timeout. This function
  206.     always buffers one character (the function holds the previous
  207.     character to be sent back). So when a call to UnListen() is issued
  208.     to end the data transmission, the buffered character is sent with an
  209.     End Or Identify (EOI) set, then UNLISTEN is sent to the device.
  210.  
  211.     How to Use:
  212.  
  213.      1) Use Listen() function (and Second() if needed).
  214.      2) Call this function to send the data byte.
  215.  
  216.  
  217.    INPUTS
  218.     char - character to transmit (0-255)
  219.  
  220.  
  221.    RESULTS
  222.  
  223.  
  224.    EXAMPLE
  225.  
  226.     /*SEND A BYTE TO THE BUS*/
  227.  
  228.     ACPtr(0xff);
  229.  
  230.  
  231.    BUGS
  232.  
  233.  
  234.    SEE ALSO
  235.     Listen(), Second()
  236.  
  237. iec.library/Listen                                         iec.library/Listen
  238.  
  239.    NAME
  240.     Listen -- Command devices on the serial bus to LISTEN.
  241.  
  242.    SYNOPSIS
  243.     Listen(device)
  244.            D0
  245.  
  246.     void Listen(UBYTE)
  247.  
  248.  
  249.    FUNCTION
  250.     This function will command a device on the serial bus to receive
  251.     data. A device number between 0 and 31 must be provided before
  252.     calling the routine. LISTEN will OR the number bit by bit to convert
  253.     it to a listen address, then transmit this data as a command onto the
  254.     serial bus. The specified device will then go into listen mode, and
  255.     be ready to accept information.
  256.  
  257.  
  258.    INPUTS
  259.     char - character to transmit (0-255)
  260.  
  261.  
  262.    RESULTS
  263.  
  264.  
  265.    EXAMPLE
  266.  
  267.     /*SEND LISTEN TO DEVICE NUMBER 8*/
  268.  
  269.     Listen(8);
  270.  
  271.  
  272.    BUGS
  273.  
  274.  
  275.    SEE ALSO
  276.     Second(), UnListen()
  277. iec.library/Second                                         iec.library/Second
  278.  
  279.    NAME
  280.     Second -- Command devices on the serial bus to LISTEN.
  281.  
  282.    SYNOPSIS
  283.     Second(secondary_address)
  284.            D0
  285.  
  286.     void Second(UBYTE)
  287.  
  288.  
  289.    FUNCTION
  290.     This function is used to send a secondary address to an I/O device
  291.     after a call to the LISTEN function has been made, and the device is
  292.     commanded to LISTEN. The function cannot be used to send a secondary
  293.     address after a call to the TALK function. A secondary address is
  294.     usually used to give setup information to a device before I/O
  295.     operations begin. When a secondary address is to be sent to a
  296.     device on the serial bus, the address must first be ORed with one
  297.     of the low level command codes: CMD_DATA, CMD_CLOSE or CMD_OPEN.
  298.     The secondary address can be any number from 0 to 14. These refer
  299.     to channels used to communicate with the disk drive. Channel 15 is
  300.     reserved as command channel.
  301.  
  302.  
  303.    INPUTS
  304.     secondary_address - a valid secondary address (0-15)
  305.  
  306.  
  307.    RESULTS
  308.  
  309.  
  310.    EXAMPLE
  311.  
  312.     /*OPEN DEVICE #8 WITH COMMAND (SECONDARY ADDRESS) #15 */
  313.  
  314.     Listen(8);
  315.     Second(CMD_OPEN|15);
  316.  
  317.  
  318.    BUGS
  319.  
  320.  
  321.    SEE ALSO
  322.     Listen()
  323. iec.library/Talk                                             iec.library/Talk
  324.  
  325.    NAME
  326.     Talk -- Command serial bus device to TALK.
  327.  
  328.    SYNOPSIS
  329.     Talk(device)
  330.          D0
  331.  
  332.     void Listen(UBYTE)
  333.  
  334.  
  335.    FUNCTION
  336.     To use this function a device number between 0 and 31 must be
  337.     provided. When called, it ORes its argument bit by bit to
  338.     convert this device number to a talk address. Then data is
  339.     transmitted as a command on the serial bus.
  340.  
  341.  
  342.    INPUTS
  343.     device - a valid device number (8-31)
  344.  
  345.  
  346.    RESULTS
  347.  
  348.  
  349.    EXAMPLE
  350.  
  351.     /*SEND TALK TO DEVICE NUMBER 8*/
  352.  
  353.     Talk(8);
  354.  
  355.  
  356.    BUGS
  357.  
  358.  
  359.    SEE ALSO
  360.     TkSA(), UnTalk()
  361. iec.library/TkSA                                             iec.library/TkSA
  362.  
  363.    NAME
  364.     TkSA -- Send secondary address after TALK.
  365.  
  366.    SYNOPSIS
  367.     TkSA(secondary_address)
  368.          D0
  369.  
  370.     void TkSA(UBYTE)
  371.  
  372.  
  373.    FUNCTION
  374.     This function transmits a secondary address onto the serial bus for
  375.     a TALK device. The function sends the number as a secondary address
  376.     command over the serial bus. This function can only be called after
  377.     a call to the TALK function. It will not work after a LISTEN. A
  378.     secondary address is usually used to give setup information to a
  379.     device before I/O operations begin.
  380.     When a secondary address is to be sent to a device on the serial
  381.     bus, the address must first be ORed with one of the low level
  382.     command codes: CMD_DATA, CMD_CLOSE or CMD_OPEN.
  383.     The secondary address can be any number from 0 to 14. These refer
  384.     to channels used to communicate with the disk drive. Channel 15 is
  385.     reserved as command channel.
  386.  
  387.  
  388.    INPUTS
  389.     secondary_address - a valid secondary address (0-15)
  390.  
  391.  
  392.    RESULTS
  393.  
  394.  
  395.    EXAMPLE
  396.  
  397.     /*OPEN DEVICE #8 WITH COMMAND (SECONDARY ADDRESS) #2 */
  398.  
  399.     Talk(8);
  400.     TkSA(CMD_OPEN|2);
  401.  
  402.  
  403.    BUGS
  404.  
  405.  
  406.    SEE ALSO
  407.     Talk()
  408. iec.library/UnTalk                                         iec.library/UnTalk
  409.  
  410.    NAME
  411.     UnTalk -- Command serial bus to UNTALK
  412.  
  413.    SYNOPSIS
  414.     UnTalk()
  415.  
  416.  
  417.     void UnTalk(void)
  418.  
  419.  
  420.    FUNCTION
  421.     This function transmits an UNTALK command onto the serial bus. All
  422.         devices previously set to TALK will stop sending data when this
  423.     command is received.
  424.  
  425.  
  426.    INPUTS
  427.  
  428.  
  429.    RESULTS
  430.  
  431.  
  432.    EXAMPLE
  433.  
  434.     /*SEND UNTALK COMMAND TO ALL DEVICES */
  435.  
  436.     UnTalk();
  437.  
  438.  
  439.    BUGS
  440.  
  441.  
  442.    SEE ALSO
  443.     Talk()
  444. iec.library/UnListen                                     iec.library/UnListen
  445.  
  446.    NAME
  447.     UnListen -- Command serial bus to UNLISTEN
  448.  
  449.    SYNOPSIS
  450.     UnListen()
  451.  
  452.  
  453.     void UnListen(void)
  454.  
  455.  
  456.    FUNCTION
  457.     This function commands all devices on the serial bus to stop
  458.     receiving data from the computer (i.e., UNLISTEN). Calling this
  459.     function results in an UNLISTEN command being transmitted onto the
  460.     serial bus. Only devices previously commanded to LISTEN are
  461.     affected. This function is normally used after the computer has
  462.     finished sending data to external devices. The sending of UNLISTEN
  463.     commands listening devices to get off the serial bus so it can be
  464.     used for other purposes.
  465.  
  466.  
  467.  
  468.    INPUTS
  469.  
  470.  
  471.    RESULTS
  472.  
  473.  
  474.    EXAMPLE
  475.  
  476.     /*SEND UNLISTEN COMMAND TO ALL DEVICES */
  477.  
  478.     UnListen();
  479.  
  480.  
  481.    BUGS
  482.  
  483.  
  484.    SEE ALSO
  485.     Listen()
  486.